package com.gimi.cloud.jimi.manage.consumer.service.prod.impl;

import com.gimi.cloud.jimi.common.enums.ResponseCodeEnum;
import com.gimi.cloud.jimi.common.exception.MsgException;
import com.gimi.cloud.jimi.common.utils.EntityVerification;
import com.gimi.cloud.jimi.common.utils.JsonUtil;
import com.gimi.cloud.jimi.common.utils.StringUtil;
import com.gimi.cloud.jimi.common.utils.reqhead.Response;
import com.gimi.cloud.jimi.common.utils.reqhead.Util;
import com.gimi.cloud.jimi.common.utils.reqhead.Verification;
import com.gimi.cloud.jimi.dto.product.LogisticsCompanyDTO;
import com.gimi.cloud.jimi.manage.consumer.feign.LogisticsFeignService;
import com.gimi.cloud.jimi.manage.consumer.service.prod.LogisticsCompanyService;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Service
public class LogisticsCompanyServiceImpl implements LogisticsCompanyService {
    private static final Logger logger = LoggerFactory.getLogger(LogisticsCompanyServiceImpl.class);

    @Autowired
	private LogisticsFeignService logisticsFeignService;
    
	@Override
	public Response logisticsCompanyPageList(String requestBody, HttpServletRequest request, HttpServletResponse response) {
		logger.info("请求参数===>" + JsonUtil.replaceNow(requestBody));
		LogisticsCompanyDTO dto = JsonUtil.jsonToBean(requestBody,LogisticsCompanyDTO.class);
		if(StringUtil.isBlank(dto.getCurrentPage())||StringUtil.isBlank(dto.getPageSize())){
			throw new MsgException(ResponseCodeEnum.PARAMETER_ERROR,"分页参数错误!");
		}
		return logisticsFeignService.LogisticsCompanypageList(dto);
	}

	@Override
	public Response getSingleLogisticsCompany(String requestBody, HttpServletRequest request, HttpServletResponse response)
			throws MsgException {
		logger.info("请求参数===>" + JsonUtil.replaceNow(requestBody));
		LogisticsCompanyDTO dto = JsonUtil.jsonToBean(requestBody,LogisticsCompanyDTO.class);
		if(StringUtil.isBlank(dto.getLcId())){
			throw new MsgException(ResponseCodeEnum.PARAMETER_ERROR,"lcId不能为空!");
		}
		return logisticsFeignService.getSingleLogisticsCompany(dto);
	}

	@Override
	public Response updateLogisticsCompany(String requestBody, HttpServletRequest request, HttpServletResponse response)
			throws MsgException {
		logger.info("请求参数===>" + JsonUtil.replaceNow(requestBody));
		LogisticsCompanyDTO dto = JsonUtil.jsonToBean(requestBody,LogisticsCompanyDTO.class);
		Verification verification = EntityVerification.checkEntity(dto);
		if (!verification.getCheckResult()) {
			Response resp = new Response();
			resp.setResponseCode(ResponseCodeEnum.PARAMETER_ERROR, verification.getMsg());
			return resp;
		} else {
			return logisticsFeignService.LogisticsCompanyAdd(dto);
		}
	}

	@Override
	public Response deleteLogisticsCompany(String requestBody, HttpServletRequest request, HttpServletResponse response)
			throws MsgException {
		logger.info("请求参数===>" + JsonUtil.replaceNow(requestBody));
		LogisticsCompanyDTO dto = JsonUtil.jsonToBean(requestBody,LogisticsCompanyDTO.class);
		Verification verification = EntityVerification.checkEntity(dto);
		if (!verification.getCheckResult()) {
			Response resp = new Response();
			resp.setResponseCode(ResponseCodeEnum.PARAMETER_ERROR, verification.getMsg());
			return resp;
		} else {
			return logisticsFeignService.deleteLogisticsCompany(dto);
		}
	}

    
}
